package cn.com.zonesion.rfiddemo.fragment.highfrequencyfragment;

import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cn.com.zonesion.rfiddemo.R;
import cn.com.zonesion.rfiddemo.base.BaseFragment;

/**
 * Created by Administrator on 2018/4/24.
 */

public class HighFrequencyBasicsFragment extends BaseFragment {
    @BindView(R.id.tty_spinner_region)
    Spinner ttySpinnerRegion;
    @BindView(R.id.tty_spinner_rf_channel)
    Spinner ttySpinnerRfChannel;
    @BindView(R.id.tty_spinner_memory_area)
    Spinner ttySpinnerMemoryArea;
    /**
     * 地区数组，用来存放常用数组
     */
    private String[] regionArray;
    /**
     * ER频道数组
     */
    private String[] rfChannelArray;
    /**
     * 内存区域数组
     */
    private String[] memoryAreaArray;
    /**
     * 对应的地区
     */
    private String region;
    /**
     * 对应的ER频道
     */
    private int rfChannel;
    /**
     * 对应的内存区域
     */
    private String memoryArea;
    /**
     * Unbinder对象，用来解除ButterKnife与Fragment对象的绑定
     */
    Unbinder unbinder;



    @Override
    public View initView() {
        View view = View.inflate(mContext, R.layout.basics_high_frequency_item, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void initData() {
        super.initData();
        init();
    }

    @Override
    public void onDestroyView() {
        //解除ButterKnife与ICBasicsFragment的绑定
        unbinder.unbind();
        super.onDestroyView();
    }
    private void init(){
        regionArray =  getResources().getStringArray(R.array.regional_setting);
        rfChannelArray =  getResources().getStringArray(R.array.er_channel);
        memoryAreaArray =  getResources().getStringArray(R.array.memory_area);
        ttySpinnerRegion.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,regionArray));
        ttySpinnerRfChannel.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,rfChannelArray));
        ttySpinnerMemoryArea.setAdapter(new ArrayAdapter<>(getActivity(),R.layout.spinner_layout,R.id.textView,memoryAreaArray));
        //ttySpinnerRegion设置适配器（地区设置）
        ttySpinnerRegion.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                region = regionArray[position];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });
        //ttySpinnerRfChannel设置适配器（EF频道设置）
        ttySpinnerRfChannel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                rfChannel = Integer.parseInt(rfChannelArray[position]);
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });
        //ttySpinnerMemoryArea设置适配器（内存区域）
        ttySpinnerMemoryArea.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
                memoryArea = memoryAreaArray[position];
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {}
        });
    }
    @OnClick({R.id.btn_regional_acquisition,R.id.btn_regional_setting,
            R.id.btn_channel_acquisition,R.id.btn_channel_setting,
            R.id.btn_power_acquisition,R.id.btn_power_setting,
            R.id.btn_scavenging,R.id.btn_start_looking_for_a_card,
            R.id.btn_read_information_scavenging,R.id.btn_read_information_read,
            R.id.btn_read_information_write})
    public void onClick(View view){
        switch (view.getId()) {
            case  R.id.btn_regional_acquisition:

                break;
            case  R.id.btn_regional_setting:

                break;
            case  R.id.btn_channel_acquisition:

                break;
            case  R.id.btn_channel_setting:

                break;
            case  R.id.btn_power_acquisition:

                break;
            case  R.id.btn_power_setting:

                break;
            case  R.id.btn_scavenging:

                break;
            case  R.id.btn_start_looking_for_a_card:

                break;
            case  R.id.btn_read_information_scavenging:

                break;
            case  R.id.btn_read_information_read:

                break;
            case  R.id.btn_read_information_write:

                break;
        }
    }
}
